import { createRouter, createWebHashHistory } from 'vue-router'
// import { Store } from 'vuex'
const routes = [
  { path: '/', redirect: '/home' },
  {
    path: '/home',
    component: () => import(/* webpackChunkName: 'Home' */ '@/views/Home.vue'),
    meta: { title: '网易云音乐' }
  },
  {
    path: '/itemmusic/:id',
    component: () =>
      import(/* webpackChunkName: 'ItemMusic' */ '@/views/ItemMusic.vue'),
    props: true,
    meta: { title: '发现好歌单' }
  },
  {
    path: '/search',
    component: () =>
      import(/* webpackChunkName: 'ItemMusic' */ '@/views/Search.vue'),
    meta: { title: '搜索音乐' }
  },
  {
    path: '/my',
    component: () =>
      import(/* webpackChunkName: 'ItemMusic' */ '@/views/My.vue'),
    meta: { title: '我的' },
    beforeEnter: (to, from, next) => {
      if (sessionStorage.getItem('token')) {
        next()
      } else {
        next('/login')
      }
    }
  },
  {
    path: '/login',
    component: () =>
      import(/* webpackChunkName: 'ItemMusic' */ '@/views/Login.vue'),
    meta: { title: '登陆页面' }
  },
  {
    path: '/comments/:id',
    component: () =>
      import(
        /* webpackChunkName: 'ItemMusic' */ '@/components/item/CommentList.vue'
      ),
    meta: { title: '评论页面' },
    props: true
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') {
//     // Store.commit('footerMusicShowStateChange', false)
//     next()
//   } else {
//     // Store.commit('footerMusicShowStateChange', true)
//     next()
//   }
// })
router.afterEach((to, from) => {
  document.title = to.meta.title
})
export default router
